﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class TechnologyRouteProcessConfig : POBaseConfig<TechnologyRouteProcessPO>
    {
        public override void InitializeData(EntityTypeBuilder<TechnologyRouteProcessPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<TechnologyRouteProcessPO> builder, ref int index)
        {
            builder.HasComment("工艺路径工序表");
            builder.Property(entity => entity.TechnologyRouteCode).ConfigColumn("TECHNOLOGY_ROUTE_CODE", "工艺路径编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.SortNumber).ConfigColumn("SORT_NUMBER", "排序").HasColumnOrder(index++);
            builder.Property(entity => entity.Description).ConfigColumn("DESCRIPTION", "描述", 100, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyProcessCode).ConfigColumn("TECHNOLOGY_PROCESS_CODE", "工艺工序编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.StateCode).ConfigColumn("STATE_CODE", "状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.AgingTime).ConfigColumn("AGING_TIME", "静置时间").HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
            builder.HasMany(entity => entity.FormulaList).WithOne(entity => entity.TechnologyRouteProcess).HasForeignKey(entity => entity.TechnologyRouteProcessId).HasConstraintName("FK_B_TECHNOLOGYFORMULA").IsRequired().OnDelete(DeleteBehavior.Restrict);
            builder.HasMany(entity => entity.RecipeList).WithOne(entity => entity.TechnologyRouteProcess).HasForeignKey(entity => entity.TechnologyRouteProcessId).HasConstraintName("FK_B_TECHNOLOGYRECIPE").IsRequired().OnDelete(DeleteBehavior.Restrict);
            builder.HasMany(entity => entity.NgRecipeList).WithOne(entity => entity.TechnologyRouteProcess).HasForeignKey(entity => entity.TechnologyRouteProcessId).HasConstraintName("FK_B_TECHNOLOGYNGRECIPE").IsRequired().OnDelete(DeleteBehavior.Restrict);
        }

        public override void MapIndex(EntityTypeBuilder<TechnologyRouteProcessPO> builder)
        {
            builder.HasIndex(entity => new { entity.TechnologyRouteCode, entity.TechnologyProcessCode, entity.SortNumber, entity.WarehouseCode }).HasDatabaseName($"IDX_{TableName}_1");
        }
    }
}
